import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import { Params } from '../atom/params2query';
import p2q from '../atom/params2query';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import render from '@feidao/web/atom/browser/render/render';
import P02 from './P02';
import P04 from './P04';

import s from './s';

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	let page_no = fd.data.params['page_no'];
	if (!page_no) {
		page_no = 1;
	}
	let page_size = fd.data.params['page_size'];
	if (!page_size) {
		page_size = 20;
	}
	const q = p2q(fd.data.params as Params);
	const query = {
		data: {
			criteria: q.criteria,
			sort: q.sort,
			page_no,
			page_size
		}
	};
	const res = await nodejs("xmedia", "moxuan_find_h5_playback_content", query);
	// 无数据渲染P04
	if (res.dataArray.length == 0) {
		render(fd, res.dataArray, P04, 'P04', 'after');
	} else {
		render(fd, res.dataArray, P02, 'P02', 'inner');
	}
}
